package com.zoulf.common.widget;

import android.content.Context;
import android.util.AttributeSet;
import com.bumptech.glide.RequestManager;
import com.zoulf.common.R;
import com.zoulf.factory.model.Author;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 头像控件
 * @author Zoulf.
 */

public class PortraitView extends CircleImageView {


  public PortraitView(Context context) {
    super(context);
  }

  public PortraitView(Context context, AttributeSet attrs) {
    super(context, attrs);
  }

  public PortraitView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
  }

  public void setup(RequestManager manager, Author author) {
    if (author == null) {
      return;
    }
    setup(manager, author.getPortrait());
  }


  public void setup(RequestManager manager, String  url) {
    setup(manager, R.drawable.default_portrait, url);
  }

  public void setup(RequestManager manager,int resouceId, String url) {
    if (url == null) {
      url = "";
    }
    manager.load(url)
        .placeholder(resouceId)
        .centerCrop()
        .dontAnimate()  // CircleImageView控件中不能使用渐变动画，会导致显示延迟
        .into(this);
  }
}
